package com.example.aboutspringboot.mapper;

import com.example.aboutspringboot.entity.Img;
import com.example.aboutspringboot.entity.Shop;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShopMapper {

    //查询所有商品信息
    @Select("select id,name,weight,issueDate,price from shop")
    List<Shop> selectShopAll();

    //查询所有图片信息
    @Select("select id,imgSrc,imgId from img")
    List<Img> selectImgAll();

    //按照id查询图片地址
    @Select("select id,imgSrc from img where id=#{id}")
    List<Img> selectImg(long id);

    //按id查询商品信息
    @Select("select id,name,weight,issueDate,price from shop where id=#{id}")
    Shop selectShopById(long id);

    //添加商品信息
    @Insert("insert into shop(name,weight,issueDate,price)values(#{name},#{weight},#{issueDate},#{price})")
    int insertShop(Shop shop);

    //添加商品图片信息
    @Insert("insert into img(id,imgSrc)values(#{id},#{imgSrc})")
    int insertImgSrc(Img img);

    //修改商品信息
    @Update("update shop set name=#{name},weight=#{weight},issueDate=#{issueDate},price=#{price} where id=#{id}")
    int updateShop(Shop shop);

    //修改商品图片信息
    @Update("update img set imgSrc=#{imgSrc} where imgId=#{imgId}")
    int updateImgSrc(Img img);

    //删除商品信息
    @Delete("delete from shop where id=#{id}")
    int deleteShop(long id);

    //删除商品图片信息
    @Delete("delete from img where imgId=#{imgId}")
    int deleteImgSrc(long imgId);
}
